package com.eagle.coders.security.beans.dao;

//import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.inject.Inject;


import com.eagle.coders.rules.service.RuleService;
import com.eagle.coders.security.beans.UsersBean;
import com.eagle.coders.security.beans.dao.annotation.JBossDrools;
import com.eagle.coders.security.beans.dao.annotation.Security;
import com.eagle.coders.server.db.DatabaseDao;
import com.eagle.coders.server.db.MyBatisDbDaoImpl;
import com.eagle.coders.server.db.annotation.MyBatis;

/**
 * 
 * @author Anees
 * 
 */
@Security
public class SecurityDaoImpl extends BaseDao implements SecurityDao {
	
	@Inject @JBossDrools RuleService droolService;
	
	@Inject @MyBatis DatabaseDao dbDao;
	
	@Override
	public UsersBean authenticateUser(UsersBean usersBean) {

		List user = new ArrayList();
		
		user.add(usersBean);
		
		System.out.println("[SecurityDaoImpl] :: dbo "+ dbDao);
		
		Map<String, Object> globals = new HashMap<String, Object>();
		globals.put("dbDao", dbDao);
		
		droolService.buildRulesEngine("com/eagle/coders/security/beans/dao/rules/SecurityRules.drl", user, globals);
		
		Collection<Object> objects = droolService.getObjects();
		
		
		UsersBean rUserBean =(UsersBean) objects.iterator().next();
		
		System.out.println("[SecurityDaoImpl] [Users] : "+rUserBean.getFirstName());
		System.out.println("[SecurityDaoImpl] [Users] : "+rUserBean.getUserRoles());
		System.out.println("[SecurityDaoImpl] [Users] : "+rUserBean.getUserRank());
		
		
		return rUserBean;
	}


}
